home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
United Public Domain Gold 2
/
United Public Domain Gold 2.iso
/
utilities
/
pu245.dms
/
pu245.adf
/
Amiga
/
Appendices
/
FunctionsAndLibraries
/
DosLibrary.doc
< prev
next >
Wrap
Text File
|
1992-05-03
|
14KB
|
427 lines
4 DOS LIBRARY
4.1 OPEN THE DOS LIBRARY
The Dos Library is automatically opened when your program is
loaded, so you do not have to open it yorself. The functions
listed in this file can therefore directly be used.
4.2 FUNCTIONS
Close()
This function closes an already opened file. Remember to
close ALL files you have opened!
Synopsis: Close( file_handle );
file_handle: (BPTR) Actually a pointer to a FileHandle
structure which has been initialized by a
previous Open() call.
CreateDir()
This function creates a new directory, AND "locks" is
automatically. (Remember to unlock the directory later on.)
Synopsis: lock = CreateDir( name );
lock: (BPTR) Actually a pointer to a FileLock structure.
If lock is equal to NULL, AmigaDOS have not been
able to create the new directory.
name: (char *) Pointer to a string containing the name
of the new directory.
CurrentDir()
This function makes a specified directory "current
directory". You need to lock the new directory (new_lock)
before you can make it the current directory. The function
returns the old current directories lock so you can unlock
it if necessary.
Synopsis: old_lock = CurrentDir( new_lock );
old_lock: (BPTR) Actually a pointer to a FileLock structure.
It is the old current directory lock.
new_lock: (BPTR) Actually a pointer to a FileLock structure.
The new current directory lock.
Delay()
This function will put your program to sleep for a specified
time period. Note that this function should be used instead
of a "dummy" loop when you want to pause a program. The
problem with wait loops is that the time it takes to execute
it depends on how fast the computer is. If you want to wait
for a while you should use this function since the delay time
will then always be the same no matter how fast or slow
the computer is. A dummy loop will also waist a lot of
processor time while the nice Delay() function will put your
task to sleep so the processor can work with other things.
Synopsis: Delay( time );
time: (ULONG) How long time you want to wait. The value
is specified in "timer units" were 50 units is
equal to 1 second. If you want to wait two minutes
you should set this field to 2 * 60 * 50 = 6000.
DeleteFile()
This function deletes a file or directory. Remember that
a directory must be empty before it can be deleted.
Synopsis: ok = DeleteFile( name );
ok: (long) Actually a Boolean. It is TRUE if AmigaDOS
could delete the file/directory, else FALSE which
means something went wrong. (Eg. disk write-
protected, directory not empty etc.)
name: (char *) Pointer to a string containing the name
of the file/directory you want to delete.
Examine()
This function can be used to get information about a file,
directory or device.
Synopsis: ok = Examine( lock, fib_ptr );
ok: (long) Actually a Boolean. It is TRUE if AmigaDOS
could get information about the file/directory,
else FALSE which means something went wrong.
lock: (BPTR) Actually a pointer to a FileLock structure.
fib_ptr: (struct FileInfoBlock *) Pointer to a FileInfoBlock
structure which will be initialized with some
information about the file/directory. IMPORTANT!
the structure must be on a 4 byte boundary.
ExNext()
This function should be used when you want to examine a
directory. You should first use the function Examine() to
see if it is a directory/device or if it simply is a file.
If it is a directory/device (fib_DirEntryType > 0), you may
call the ExNext() function until you receive an error
message.
Synopsis: ok = ExNext( lock, fib_ptr );
ok: (long) Actually a Boolean. It is TRUE if AmigaDOS
could get information about a file/directory in the
directory/device, else FALSE which means something
went wrong.
lock: (BPTR) Actually a pointer to a FileLock structure.
fib_ptr: (struct FileInfoBlock *) Pointer to a FileInfoBlock
structure which will be initialized with some
information about the file/directory. IMPORTANT!
the structure must be on a 4 byte boundary.
Info()
This function returns information about a specified disk. You
specify which disk by either lock that disk, or a file/
directory on that disk.
Synopsis: ok = Info( lock, info_data );
ok: (long) Actually a Boolean. It is TRUE if AmigaDOS
could get information about the disk, else FALSE
which means something went wrong.
lock: (BPTR) Actually a pointer to a FileLock structure.
info_data: (struct InfoData *) Pointer to an InfoData
structure which will be initialized by the Info()
function. The problem with this structure is that
it must be on a four byte boundary, so you need
to use the function AllocMem() to get the right
type of memory for the structure. (See Example.)
IoErr()
This function can be used to get more information about an
error message. Whenever you have used an AmigaDOS function
which did not work properly (you have received an error
message), you call this function and it will return an
explanation.
Synopsis: error = IoErr();
error: (long) This field contains a flag returned by
IoErr() which can be: (I do not think I need
to explain what they mean.)
ERROR_NO_FREE_STORE
ERROR_TASK_TABLE_FULL
ERROR_LINE_TOO_LONG
ERROR_FILE_NOT_OBJECT
ERROR_INVALID_RESIDENT_LIBRARY
ERROR_NO_DEFAULT_DIR
ERROR_OBJECT_IN_USE
ERROR_OBJECT_EXISTS
ERROR_DIR_NOT_FOUND
ERROR_OBJECT_NOT_FOUND
ERROR_BAD_STREAM_NAME
ERROR_OBJECT_TOO_LARGE
ERROR_ACTION_NOT_KNOWN
ERROR_INVALID_COMPONENT_NAME
ERROR_INVALID_LOCK
ERROR_OBJECT_WRONG_TYPE
ERROR_DISK_NOT_VALIDATED
ERROR_DISK_WRITE_PROTECTED
ERROR_RENAME_ACROSS_DEVICES
ERROR_DIRECTORY_NOT_EMPTY
ERROR_TOO_MANY_LEVELS
ERROR_DEVICE_NOT_MOUNTED
ERROR_SEEK_ERROR
ERROR_COMMENT_TOO_BIG
ERROR_DISK_FULL
ERROR_DELETE_PROTECTED
ERROR_WRITE_PROTECTED
ERROR_READ_PROTECTED
ERROR_NOT_A_DOS_DISK
ERROR_NO_DISK
ERROR_NO_MORE_ENTRIES
Lock()
This function "locks" a file so no other processes may alter
the contents (SHARED_LOCK). You can even prevent other
processes to read the file (EXCLUSIVE_LOCK).
Synopsis: lock = Lock( name, mode );
lock: (BPTR) Actually a pointer to a FileLock structure.
name: (char *) Pointer to a text string which contains
the file/directory name.
mode: (long) Accessmode:
SHARED_LOCK: Other tasks may read the file.
ACCESS_READ: - " -
EXCLUSIVE_LOCK: No other tasks may use this f.
ACCESS_WRITE: - " -
Open()
This function opens a file. Remember, before you can read/
write files you have to open them.
Synopsis: file_handle = Open( file_name, mode );
file_handle: (BPTR) Actually a pointer to a FileHandle
structure. If the system could not open the file
with our requirements Open() returns NULL.
file_name: (char *) Pointer to a text string which contains
the file name including any necessary devices/
directories.
mode: (long) When you open a file you need to tell the
system what you are going to do with it. This
field should therefore contain one of the
following flags:
MODE_OLDFILE: Opens an existing file for
reading and writing.
MODE_NEWFILE: Opens a new file for writing.
(If the file already exist it
is deleted.)
MODE_READWRITE: Opens an old file with an
exclusive lock. (The file is
automatically locked with an
EXCLUSIVE_LOCK.)
MODE_READONLY: Same as MODE_OLDFILE.
Read()
This function reads a specified number of bytes from a file.
Synopsis: bytes_read = Read( file_handle, buffer, size );
bytes_read: (long) Number of bytes actually read. Even if
you tell AmigaDOS that you want to read x
number of bytes, it is not certain that you
actually can do it. The file is maybe corrupted,
not as big as you thought etc.
file_handle: (BPTR) Actually a pointer to a FileHandle
structure which has been initialized by a
previous Open() call.
buffer: (char *) Pointer to the data buffer you want to
read the data into.
size: (long) Number of bytes you want to read.
Rename()
This function renames a file or directory. You can even
move a file between directories by renaming it. (For example,
Rename( "df0:Documents/Sale.doc", "df0:Letters/Sale.doc" );
will move the file Sale.doc from the directory "Documents"
to directory "Letters". Note! You can not rename a file from
one volume to another.)
Synopsis: ok = Rename( old_name, new_name );
ok: (long) Actually a Boolean. It is TRUE if AmigaDOS
could rename the file/directory, else FALSE which
means something went wrong. (Eg. disk write
-protected.)
old_name: (char *) Pointer to a string containing the old
file/directory name.
new_name: (char *) Pointer to a string containing the new
file/directory name.
Seek()
This function moves the "file cursor" inside a file:
Synopsis: old_pos = Seek( file_handle, new_pos, mode );
old_pos: (long) Previous position in the file, or -1 if
an error occurred.
file_handle: (BPTR) Actually a pointer to a FileHandle
structure which has been initialized by a
previous Open() call.
new_pos: (long) New position relative to the "mode".
mode: (long) The new_pos can be relative to:
OFFSET_BEGINNING: Beginning of the file.
OFFSET_CURRENT: Current position.
OFFSET_END: The end of the file.
SetComment
This function attach a comment to a file or directory.
Synopsis: ok = SetComment( name, comment );
ok: (long) Actually a Boolean. It is TRUE if AmigaDOS
could attach the new comment, else FALSE which
means something went wrong. (Eg. disk write-
protected.)
name: (char *) Pointer to a string containing the name
of the file/directory you want to attach the
comment to.
comment: (char *) Pointer to a string containing the
comment. (A comment may be up to 80 characters
long.)
SetProtection()
This function alters the protection bits of a file.
You can set following flags:
FIBF_DELETE : the file/directory can not be deleted.
FIBF_EXECUTE : the file can not be executed.
FIBF_WRITE : you can not write to the file.
FIBF_READ : you can not read the file.
FIBF_ARCHIVE : Archive bit.
FIBF_PURE : Pure bit.
FIBF_SCRIPT : Script bit.
(Note! All of the flags are for the moment not working!)
Synopsis: ok = SetProtection( name, mask );
ok: (long) Actually a Boolean. It is TRUE if AmigaDOS
could alter the protection bits, else FALSE which
means something went wrong. (Eg. disk write-
protected.)
name: (char *) Pointer to a string containing the name
of the file/directory you want to change the
protection bits.
mask: (long) The protection bits. (For example, if you
want to make the file/directory not deletable,
and that it can not be executed you should set the
protection bits: FIBF_DELETE | FIBF_EXECUTE.)
UnLock()
This function unlocks a previously locked file: (Remember to
unlock ALL files you have locked!)
Synopsis: Unlock( lock );
lock: (BPTR) Actually a pointer to FileLock structure
which has been initialized by a previous Lock()
call.
Write()
This function writes a specified number of bytes to a file.
Synopsis: bytes_wr = Write( file_handle, buffer, size );
bytes_wr: (long) Number of bytes actually written. Even if
you tell AmigaDOS that you want to write x number
of bytes, it is not certain that you actually
can do it. Maybe the disk was full, write-
protected etc.
file_handle: (BPTR) Actually a pointer to a FileHandle
structure which has been initialized by a
previous Open() call.
buffer: (char *) Pointer to the data buffer which you
want to write.
size: (long) Number of bytes you want to write.